local mingyong = fk.CreateSkill {
  name = "lingling__mingyong",
}

Fk:loadTranslationTable{
  ["lingling__mingyong"] = "明用",
  [":lingling__mingyong"] = "出牌阶段限一次，你可以交给一名其他角色两张牌，其下回合首次造成伤害后，你回复1点体力。",

  ["#lingling__mingyong"] = "明用：交给一名其他角色两张牌，其下回合首次造成伤害后，你回复1点体力。",

  ["@@lingling__mingyong"] = "明用",
}

mingyong:addEffect("active", {
  anim_type = "support",
  max_phase_use_time = 1,
  card_num = 2,
  card_filter = function(self, player, to_select, selected)
    return #selected < 2
  end,
  target_num = 1,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 and to_select ~= player
  end,
  on_use = function(self, room, use)
    local player = use.from
    local target = use.tos[1]
    room:addTableMark(target, "@@lingling__mingyong", player.id)
    room:obtainCard(target, use.cards, nil, fk.ReasonGive, player, mingyong.name)
  end
})
mingyong:addEffect(fk.TurnEnd, {
  is_delay_effect = true,
  mute = true,
  late_refresh = true,
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("@@lingling__mingyong") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@@lingling__mingyong", 0)
  end,
})
mingyong:addEffect(fk.Damage, {
  anim_type = "support",
  is_delay_effect = true,
  can_trigger = function (self, event, target, player, data)
    if target and player.room:getCurrent() == target and table.contains(target:getTableMark("@@lingling__mingyong"), player.id) and
      not player.dead and player:isWounded() then
      local room = player.room
      local mark = target:getMark("lingling__mingyong_damage-turn")
      if mark == 0 then
        player.room.logic:getActualDamageEvents(1, function(e)
          local damage = e.data
          if target == damage.from then
            mark = e.id
            room:setPlayerMark(target, "lingling__mingyong_damage-turn", mark)
            return true
          end
          return false
        end, Player.HistoryTurn)
      end
      return mark == room.logic:getCurrentEvent().id
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    player.room:recover{
      who = player,
      num = 1,
      skillName = mingyong.name,
      recoverBy = player,
    }
  end
})

return mingyong
